const Router = require('koa-router')
const { Website } = require('@/app/models/website')
const { Auth } = require('@/middleware/auth')

const router = new Router({
  //统一这是前缀
  prefix: '/api/v1/website' 
})

//保存基本信息
router.post('/saveWebInfo',async ctx => {
  const websiteItem = {
    name: ctx.request.body.name,
    address: ctx.request.body.address,
    telephone: ctx.request.body.telephone,
    e_mail: ctx.request.body.e_mail,
    disable_ip: ctx.request.body.disable_ip,
    logo: ctx.request.body.logo,
    wx_code: ctx.request.body.wx_code
  }
  await Website.create(websiteItem)
  ctx.body = global.responseData(null, '更新成功')
})
//查询基本信息
router.get('/getWebInfo',async ctx => {
  const website = await Website.findOne({
    order:[
      ['updated_at','DESC']
    ]
  })
  ctx.body = global.responseData(website)
})

module.exports = router